package pl.com.like.sequoia.web.vo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.util.Assert;

import pl.com.like.sequoia.model.bio.BioObjectHandler;
import pl.com.like.sequoia.model.bio.BioParam;
import pl.com.like.sequoia.model.bio.enums.PdbDefEnum;

/**
 * Object handle extra data about PDB object.
 * 
 * @author pwolanski
 * 
 */
public class PdbObjectDataHandler implements IPdbObjectDataHandler {

	private static final long serialVersionUID = 8898754810150413372L;
	private Map<PdbDefEnum, String> properties;
	private String classification;
	private String name;
	private String technique;
	private String title;
	private String downloadUrl;
	private Object parameters;

	public PdbObjectDataHandler(String name, Map<PdbDefEnum, String> properties) {
		Assert.notNull(name);
		Assert.notNull(properties);
		setName(name);
		importProperties(properties);
	}

	public PdbObjectDataHandler(BioObjectHandler object) {
		Assert.notNull(object);
		List<BioParam> params = object.getBioParams();
		Map<PdbDefEnum, String> properties = new HashMap<PdbDefEnum, String>();
		for (BioParam item : params) {
			PdbDefEnum keyItem = item.getKey();
			String valueItem = item.getValue();
			properties.put(keyItem, valueItem);
		}
		setName(object.getName());
		importProperties(properties);
	}

	private void importProperties(Map<PdbDefEnum, String> properties) {
		Assert.notNull(properties);
		setProperties(properties);
		setClassification(properties.get(PdbDefEnum.CLASSIFICATION));
		setTechnique(properties.get(PdbDefEnum.TECHNIQUE));
		setTitle(properties.get(PdbDefEnum.TITLE));
	}
	/** {@inheritDoc} */
	public String getClassification() {
		return classification;
	}

	public String getDownloadUrl() {
		return downloadUrl;
	}

	/** {@inheritDoc} */
	public String getName() {
		return name;
	}

	public Object getParameters() {
		return parameters;
	}

	public Map<PdbDefEnum, String> getProperties() {
		return properties;
	}

	/** {@inheritDoc} */
	public String getProperty(PdbDefEnum key) {
		return properties.get(key);
	}

	/** {@inheritDoc} */
	public String getTechnique() {
		return technique;
	}

	/** {@inheritDoc} */
	public String getTitle() {
		return title;
	}

	public void setClassification(String classification) {
		this.classification = classification;
	}

	public void setDownloadUrl(String downloadUrl) {
		this.downloadUrl = downloadUrl;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setParameters(Object parameters) {
		this.parameters = parameters;
	}

	public void setProperties(Map<PdbDefEnum, String> properties) {
		this.properties = properties;
	}

	public void setTechnique(String technique) {
		this.technique = technique;
	}

	public void setTitle(String title) {
		this.title = title;
	}

}
